function a = of_nopt(x)
data_struct = load('data_nopt.mat');
prices = double(data_struct.prices);
segNP = double(data_struct.segNP);
nProducts = length(prices);
segQ = double(data_struct.segQ);
segScale = double(data_struct.segScale);
uniqSeg = double(data_struct.uniqSeg);
uniqSeg_size = size(uniqSeg);
sharepairs = double(data_struct.sharepairs);
szpairs = double(data_struct.szpairs);
nNewSegments = uniqSeg_size(1);
upMat = data_struct.upMat;
os = double(data_struct.os);
[y1,y2,~]=ind2sub(size(upMat),find(upMat));
u = zeros(nNewSegments,3+nProducts);
usub = zeros(nNewSegments,nProducts);
einpreis = uniqSeg(:,4);
for i = 1:nNewSegments
    u(i,:) = [uniqSeg(i,1)+1,y1(i),y2(i),os(uniqSeg(i,3)+1,:)];
    usub(i,:) = [os(uniqSeg(i,3)+1,:)];
    usub(i,y2(i)) = 0;
end
a = 0;
for i = 1:nNewSegments
    if nProducts == 6
        probs(i) = (1-sharepairs)*max(0,1-((exp(segNP(u(i,1)))+u(i,4)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
                +u(i,5)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+u(i,6)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
                +u(i,7)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+u(i,8)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
                +u(i,9)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))/...
                (exp(1/segScale(u(i,1))*(segQ(u(i,3),u(i,1))-einpreis(i)))+exp(segNP(u(i,1)))+usub(i,1)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
                +usub(i,2)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+usub(i,3)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
                +usub(i,4)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+usub(i,5)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
                +usub(i,6)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))))...
                +sharepairs*max(0,(1-((exp(segNP(u(i,1)))+u(i,4)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
                +u(i,5)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+u(i,6)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
                +u(i,7)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+u(i,8)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
                +u(i,9)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))/...
                (exp(1/segScale(u(i,1))*(segQ(u(i,3),u(i,1))-einpreis(i)))+exp(segNP(u(i,1)))+usub(i,1)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
                +usub(i,2)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+usub(i,3)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
                +usub(i,4)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+usub(i,5)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
                +usub(i,6)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))))^szpairs);
    elseif nProducts == 12
        probs(i) = max(0,1-((exp(segNP(u(i,1)))+u(i,4)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
        +u(i,5)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+u(i,6)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
        +u(i,7)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+u(i,8)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
        +u(i,9)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6)))+u(i,10)*exp(1/segScale(u(i,1))*(segQ(7,u(i,1))-prices(7)))...
        +u(i,11)*exp(1/segScale(u(i,1))*(segQ(8,u(i,1))-prices(8)))+u(i,12)*exp(1/segScale(u(i,1))*(segQ(9,u(i,1))-prices(9)))...
        +u(i,13)*exp(1/segScale(u(i,1))*(segQ(10,u(i,1))-prices(10)))+u(i,14)*exp(1/segScale(u(i,1))*(segQ(11,u(i,1))-prices(11)))...
        +u(i,15)*exp(1/segScale(u(i,1))*(segQ(12,u(i,1))-prices(12))))/...
        (exp(1/segScale(u(i,1))*(segQ(u(i,3),u(i,1))-einpreis(i)))+exp(segNP(u(i,1)))+usub(i,1)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
        +usub(i,2)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+usub(i,3)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
        +usub(i,4)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+usub(i,5)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
        +usub(i,6)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6)))+usub(i,7)*exp(1/segScale(u(i,1))*(segQ(7,u(i,1))-prices(7)))...
        +usub(i,8)*exp(1/segScale(u(i,1))*(segQ(8,u(i,1))-prices(8)))+usub(i,9)*exp(1/segScale(u(i,1))*(segQ(9,u(i,1))-prices(9)))...
        +usub(i,10)*exp(1/segScale(u(i,1))*(segQ(10,u(i,1))-prices(10)))+usub(i,11)*exp(1/segScale(u(i,1))*(segQ(11,u(i,1))-prices(11)))...
        +usub(i,12)*exp(1/segScale(u(i,1))*(segQ(12,u(i,1))-prices(12))))));
    end
end
if  nProducts == 6
     for i = 1:nNewSegments
        a = a-x(i)*(segScale(u(i,1))*(-reallog((exp(segNP(u(i,1)))+u(i,4)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
            +u(i,5)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+u(i,6)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
            +u(i,7)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+u(i,8)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
            +u(i,9)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))/(1-probs(i))...
            -(exp(segNP(u(i,1)))+usub(i,1)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
            +usub(i,2)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+usub(i,3)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
            +usub(i,4)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+usub(i,5)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
            +usub(i,6)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6))))...
            ))+segQ(u(i,3),u(i,1))-prices(u(i,2)));
    end
elseif nProducts == 12
    for i = 1:nNewSegments
        a = a-x(i)*(segScale(u(i,1))*(reallog(1-probs(i))-reallog(exp(segNP(u(i,1)))+u(i,4)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
            +u(i,5)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+u(i,6)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
            +u(i,7)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+u(i,8)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
            +u(i,9)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6)))+u(i,10)*exp(1/segScale(u(i,1))*(segQ(7,u(i,1))-prices(7)))...
            +u(i,11)*exp(1/segScale(u(i,1))*(segQ(8,u(i,1))-prices(8)))+u(i,12)*exp(1/segScale(u(i,1))*(segQ(9,u(i,1))-prices(9)))...
            +u(i,13)*exp(1/segScale(u(i,1))*(segQ(10,u(i,1))-prices(10)))+u(i,14)*exp(1/segScale(u(i,1))*(segQ(11,u(i,1))-prices(11)))...
            +u(i,15)*exp(1/segScale(u(i,1))*(segQ(12,u(i,1))-prices(12)))...
            -(1-probs(i))*(exp(segNP(u(i,1)))+usub(i,1)*exp(1/segScale(u(i,1))*(segQ(1,u(i,1))-prices(1)))...
            +usub(i,2)*exp(1/segScale(u(i,1))*(segQ(2,u(i,1))-prices(2)))+usub(i,3)*exp(1/segScale(u(i,1))*(segQ(3,u(i,1))-prices(3)))...
            +usub(i,4)*exp(1/segScale(u(i,1))*(segQ(4,u(i,1))-prices(4)))+usub(i,5)*exp(1/segScale(u(i,1))*(segQ(5,u(i,1))-prices(5)))...
            +usub(i,6)*exp(1/segScale(u(i,1))*(segQ(6,u(i,1))-prices(6)))+usub(i,7)*exp(1/segScale(u(i,1))*(segQ(7,u(i,1))-prices(7)))...
            +usub(i,8)*exp(1/segScale(u(i,1))*(segQ(8,u(i,1))-prices(8)))+usub(i,9)*exp(1/segScale(u(i,1))*(segQ(9,u(i,1))-prices(9)))...
            +usub(i,10)*exp(1/segScale(u(i,1))*(segQ(10,u(i,1))-prices(10)))+usub(i,11)*exp(1/segScale(u(i,1))*(segQ(11,u(i,1))-prices(11)))...
            +usub(i,12)*exp(1/segScale(u(i,1))*(segQ(12,u(i,1))-prices(12))))))+segQ(u(i,3),u(i,1))-prices(u(i,2)));
    end
end
end